# -*- coding:utf-8 -*-

# @File     :misc
# @Author   :Yupeng
# @Date     :2018/11/30 11:04

from datetime import datetime


def months(start_year, start_month, end_year, end_month):
    '''
    月份的迭代器，闭区间
    :param start_year: 起始年份
    :param start_month: 起始月份
    :param end_year: 终点年份
    :param end_month: 终点月份
    :return:
    '''
    month, year = start_month, start_year

    while (year, month) <= (end_year, end_month):
        yield year * 100 + month
        month += 1
        if month > 12:
            month = 1
            year += 1


def get_current_date():
    now = datetime.now()
    y = now.year
    m = now.month
    return y * 100 + m


def get_6_month_before_now():
    now = datetime.now()
    y = now.year
    m = now.month
    if m >= 6:
        return y * 100 + m - 5
    else:
        return (y - 1) * 100 + 7 + m
